package com.ruicar.afs.cloud.batch.config;

import com.ruicar.afs.cloud.batch.frame.bean.BatchResourceHolder;
import com.ruicar.afs.cloud.common.core.constant.CommonConstants;
import com.ruicar.afs.cloud.common.core.exception.AfsBaseException;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.Map;

@Data
@Configuration
@ConfigurationProperties(prefix = BatchJdbcProperties.PREFIX)
public class BatchJdbcProperties {
    public static final String PREFIX="com.ruicar.afs.cloud.batch";
    private Map<String,JdbcConfig> jdbcList;

    @PostConstruct
    public void init(){
        if(jdbcList==null||!jdbcList.containsKey(CommonConstants.DEFAULT)){
            throw new AfsBaseException("连接配置错误[default]连接不存在");
        }
        BatchResourceHolder.jdbcList = jdbcList;
    }
}
